package st.business.tepth.business.user.busnumber.preholder.repair;

import com.alibaba.fastjson.TypeReference;

import io.reactivex.disposables.Disposable;
import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.PreWorkInfoBean;
import st.business.tepth.config.Url;
import st.shadow.library.core.net.callback.IError;
import st.shadow.library.core.net.callback.ISuccess;
import st.shadow.library.core.net.data.ObjConverter;
import st.shadow.library.core.net.rx.RxRestClient;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-04-11 15:38
 */

public class PreRepairModel implements PreRepairContract.Model{
    @Override
    public Disposable getInfo(String token, int repairId, final OnDataConvertListener<PreWorkInfoBean> listener) {
        return RxRestClient.builder()
                .url(Url.GetRepairWating)
                .params("repairId", repairId)
                .params("token", token)
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        listener.convert(convertToCompleteInfo(response));
                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        listener.error(code, msg);
                    }
                })
                .build()
                .post();
    }

    private PreWorkInfoBean convertToCompleteInfo(String response) {
        return new ObjConverter<PreWorkInfoBean>().convert(response
                , new TypeReference<PreWorkInfoBean>() {
                });
    }
}
